<%@tag import="by.epam.communalservices.entity.JkhObject"%>
<%@tag import="by.epam.communalservices.dao.jdbc.JdbcDaoJkhObject"%>
<%@tag import="java.sql.Connection"%>
<%@tag import="java.util.List"%>

<%@ attribute name="name" required="true"%>
<%@ attribute name="selected" required="true"%>
<%@ attribute name="attr"%>
<%@ attribute name="none"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<select name="${name}" ${attr}>
    <c:if test="${!empty none}">
		<OPTION VALUE='' ${selected=='' ? 'SELECTED' : ''}><c:out value="выбрать объект"/></OPTION>
	</c:if>
	<%
		Long selected = 0L;
	    try {
	        selected = Long.parseLong(getJspContext().getAttribute("selected").toString());
	    } catch (NumberFormatException e) {
	    }
	    	JdbcDaoJkhObject objectDao = new JdbcDaoJkhObject((Connection) request.getSession().getAttribute("currentConnection"));
	        List<JkhObject> objectList = objectDao.findAll();

	        for (JkhObject item : objectList) {
	            out.println("<OPTION VALUE='" + item.getId() + "' " + (item.getId() == selected ? "SELECTED" : "") + ">"
	                    + item.getId().toString()+ ". "+ item.getAddress() + "</OPTION>");
	        }
	%>

</select>
